<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <script type="text/javascript" src="../js/vue.js"></script>
    <title>v-text指令</title>
</head>
<body>
    <div id="root">
       <h2>当前的n值是：{{n}}</h2>
       <button @click="add">点我n+1</button>
       <button @click="bye">销毁vm</button>
    </div>
    <script type="text/javascript">
        const vm = new Vue({
            el:"#root",
            // template:`<div><h2>当前的n值是：{{n}}</h2> <button @click="add">点我n+1</button></div>`,
            data(){
                return {
                    n:0
                }
            },
            methods:{
                add(){
                    this.n += 1;
                },
                bye(){
                    console.log('销毁vm')
                    this.$destroy()

                }
            },
            beforeCreate(){
                console.log('beforeCreate')
                // console.log(this)//vm中此时没有n（_data）和方法(add) 
                // debugger;
            },
            created(){
                console.log('created')
                // console.log(this)//vm中此时有n（_data）和方法(add)
                // debugger;
            },
            beforeMount(){
                console.log('beforeMount')
                // console.log(this)
                // debugger;
            },
            mounted(){
                console.log('mounted')
                // console.log(this)
                // debugger;
            },
            beforeUpdate(){
                console.log('beforeUpdate')
            },
            updated(){
                console.log('updated')
            },
            beforeDestroy(){
                console.log('beforeDestroy')
                this.add()//页面数据不会发生修改
                console.log('beforeDestroy:',this.n)
            },
            destroyed(){
                console.log('destroyed')
            } 
        })

    </script>
</body>
</html>